from django.db import models


# Create your models here.

class UserInfo(models.Model):
    name = models.CharField(verbose_name="姓名", max_length=16, db_index=True)
    age = models.PositiveIntegerField(verbose_name="年龄")
    email = models.CharField(verbose_name="邮箱", max_length=128, unique=True)
    amount = models.DecimalField(verbose_name="余额", max_digits=10, decimal_places=2, default=0)
    register_date = models.DateField(verbose_name="注册时间", auto_now=True)


class Goods(models.Model):
    title = models.CharField(verbose_name="标题", max_length=32)
    # detail = models.CharField(verbose_name="详细信息", max_length=255)
    detail = models.TextField(verbose_name="详细信息")
    price = models.DecimalField(verbose_name="价格", max_digits=10, decimal_places=2, default=0)
    count = models.PositiveBigIntegerField(verbose_name="库存", default=0)


# 表一对多关系
# 表一对多关系


# 表 一对多
class Department(models.Model):
    title = models.CharField(max_length=16)


class Empolyee(models.Model):
    name = models.CharField(verbose_name="姓名", max_length=16)
    age = models.IntegerField(verbose_name="年龄")
    email = models.CharField(verbose_name="邮箱", max_length=128, unique=True)
    department = models.ForeignKey(to="Department", to_field="id", on_delete=models.CASCADE)

    class Meta:
        db_table = "employee"


# 表 多对多
class Boy(models.Model):
    name = models.CharField(verbose_name="姓名", max_length=16)


class Girl(models.Model):
    name = models.CharField(verbose_name="姓名", max_length=16)


class B2G(models.Model):
    bid = models.ForeignKey(verbose_name="男生id", to="Boy", to_field="id", on_delete=models.CASCADE)
    gid = models.ForeignKey(verbose_name="女生id", to="Girl", to_field="id", on_delete=models.CASCADE)
    address = models.CharField(verbose_name="地点", max_length=32)
